﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DeliverablesReport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverablesProjectNames", con);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            ddlProject.DataTextField = "WebName";
            ddlProject.DataValueField = "WebName";

            con.Open();
            ddlProject.DataSource = cmd.ExecuteReader();
            ddlProject.DataBind();
            ddlProject.Items.Insert(0, "All");
            con.Close();


            System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand("GetDeliverablesProjectStatus", con);

            cmd1.CommandType = System.Data.CommandType.StoredProcedure;

            ddlStatus.DataTextField = "Status";
            ddlStatus.DataValueField = "Status";

            con.Open();
            ddlStatus.DataSource = cmd1.ExecuteReader();
            ddlStatus.DataBind();
            ddlStatus.Items.Insert(0, "All");

            con.Close();
        }
    }

    protected void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
    {
        String WebName  = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "WebName"));



        // This event is raised for the header, the footer, separators, and items.
        //e.Item.DataItem
        // Execute the following logic for Items and Alternating Items.
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverables", con);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@WebName", WebName));

            if (ddlStatus.SelectedValue != "All")
                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Status", ddlStatus.SelectedValue));

            con.Open();
            ((GridView)e.Item.FindControl("GridView1")).DataSource = cmd.ExecuteReader();
            ((GridView)e.Item.FindControl("GridView1")).DataBind();
            con.Close();


        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["FastSharePoint"].ConnectionString;

        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(sqlCon);
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("GetDeliverablesProjects", con);

        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        if (ddlProject.SelectedValue != "All")
            cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@WebName", ddlProject.SelectedValue));

        con.Open();
        Repeater1.DataSource = cmd.ExecuteReader();
        Repeater1.DataBind();
        con.Close();
        
    }
}
